﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PSE.AuditLogging.StorageService.Management.ServiceContracts;
using System.ServiceModel;

namespace PSE.AuditLogging.StorageService.ServiceImplementation
{
    [ServiceBehavior(IncludeExceptionDetailInFaults = true)]
    public class ServiceManager : IServiceManager
    {
        #region IServiceManager Members

        public bool StartProduct(string productId)
        {
            ServiceExecutor executor = ServiceExecutor.GetInstance();
            if (executor != null)
                return executor.StartProduct(productId);
            else
                throw new Exception("Cannot retrieve the ServiceExecutor instance");
        }

        public bool StopProduct(string productId)
        {
            ServiceExecutor executor = ServiceExecutor.GetInstance();
            if (executor != null)
                return executor.StopProduct(productId);
            else
                throw new Exception("Cannot retrieve the ServiceExecutor instance");
        }

        public bool RestartProduct(string productId)
        {
            ServiceExecutor executor = ServiceExecutor.GetInstance();
            if (executor != null)
                return executor.RestartProduct(productId);
            else
                throw new Exception("Cannot retrieve the ServiceExecutor instance");
        }

        public List<string> GetRunningProducts()
        {
            ServiceExecutor executor = ServiceExecutor.GetInstance();
            if (executor != null)
                return executor.GetRunningProducts();
            else
                throw new Exception("Cannot retrieve the ServiceExecutor instance");
        }

        public List<string> GetRunningInstances(string productId)
        {
            ServiceExecutor executor = ServiceExecutor.GetInstance();
            if (executor != null)
                return executor.GetRunningInstances(productId);
            else
                throw new Exception("Cannot retrieve the ServiceExecutor instance");
        }

        #endregion
    }
}
